﻿using Engine;
using Engine.Graphics;

namespace Game
{
    public class MedkitBlock : Block
    {
        public const int Index = 314;

        private BlockMesh m_standaloneBlockMesh = new BlockMesh();

        public Texture2D texture = ContentManager.Get<Texture2D>("Textures/items/medkit");

        public override void Initialize()
        {
            Model model = ContentManager.Get<Model>("Models/Plate");
            Matrix boneAbsoluteTransform = BlockMesh.GetBoneAbsoluteTransform(model.FindMesh("Plate").ParentBone);
            m_standaloneBlockMesh.AppendModelMeshPart(model.FindMesh("Plate").MeshParts[0], boneAbsoluteTransform * Matrix.CreateTranslation(0f, 0f, 0f) * Matrix.CreateRotationX(1.5707f), makeEmissive: false, flipWindingOrder: false, doubleSided: true, flipNormals: false, Color.White);
            base.Initialize();
        }

        public override void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
        {
            generator.GenerateShadedMeshVertices(this, x, y, z, m_standaloneBlockMesh, Color.White, null, null, geometry.SubsetOpaque);
        }

        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            BlocksManager.DrawMeshBlock(primitivesRenderer, m_standaloneBlockMesh, texture, color, 1.5f * size, ref matrix, environmentData);
        }
    }
}